package org.tongdao.yulong.factorybean;

import org.springframework.beans.factory.FactoryBean;

/**
 * @Description: TODO
 * @author: 殷玉龙
 * @date: 2021年01月11日 下午5:30
 */
public class ToyFactoryBean implements FactoryBean<Toy> {

  public ToyFactoryBean() {
    System.out.println("ToyFactoryBean 初始化了。。。");
  }

  private Child child;

  public void setChild(Child child) {
    this.child = child;
  }

  @Override
  public Toy getObject() throws Exception {
    switch (child.getWantToy()) {
      case "ball":
        return new Ball("ball");
      case "car":
        return new Car("car");
      default:
        // SpringFramework2.0开始允许返回null
        // 之前的1.x版本是不允许的
        return null;
    }
  }

  @Override
  public Class<?> getObjectType() {
    return Toy.class;
  }

  @Override
  public boolean isSingleton() {
    return false;
  }
}
